package com.xm.service.background;

import com.xm.dao.background.CommoditySpecificationDao;
import com.xm.entity.CommoditySpecification;
import com.xm.exception.SqlErrorException;

import java.util.List;

/**
 * 商品规格
 * @author 康文程
 * @date 2024-1-9 下午 07:05
 */
public class CommoditySpecificationService {
    private final CommoditySpecificationDao dao = new CommoditySpecificationDao();
    /**
     * 根据commodity_id查询商品规格
     * @param commodityId 商品ID
     * @return 商品规格列表
     */
    public List<CommoditySpecification> getCommoditySpecificationsByCommodityId(Integer commodityId) {
        return dao.getCommoditySpecificationsByCommodityId(commodityId);
    }
    /**
     * 新增商品规格
     *
     * @param specification 规格对象
     * @return 新增成功返回true，失败返回false
     * @throws SqlErrorException SQL执行异常
     */
    public boolean insertCommoditySpecification(CommoditySpecification specification) throws SqlErrorException {
        return dao.insertCommoditySpecification(specification);
    }
    /**
     * 根据 specification_type_id 和 commodity_id 删除 commodity_specification
     *
     * @param specificationTypeId 规格类型ID
     * @param commodityId         商品ID
     * @return 删除成功返回 true，失败返回 false
     */
    public boolean deleteCommoditySpecification(Integer specificationTypeId, Integer commodityId) throws SqlErrorException {
        return dao.deleteCommoditySpecification(specificationTypeId, commodityId);
    }

    /**
     * 根据 specification_id 和 commodity_id 删除 commodity_specification
     * @param specificationId 规格ID
     * @param commodityId     商品ID
     * @return 删除成功返回 true，失败返回 false
     */
    public boolean deleteCommoditySpecificationByIds(Integer specificationId, Integer commodityId) throws SqlErrorException {
        return dao.deleteCommoditySpecificationByIds(specificationId, commodityId);
    }
}
